package com.woniu.map.remote.url;

import com.woniu.internalcommon.constant.AmapConfigConstants;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.response.TrackResponse;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

@Service
public class AmapUrl{


    @Value("${map.key}")
    private String mapKey;

    /**
     *
     * 驾车路线规划 请求url
     * 返回基础信息
     * @param originLongitude 起始经度
     * @param originLatitude  起始纬度
     * @param destLongitude  到达经度
     * @param destLatitude   到达纬度
     */
    //https://restapi.amap.com/v3/direction/driving?origin=116.481028,39.989643&destination
    // =116.465302,40.004717&extensions=base&key=7367d4e858a51c328ce549ac315007d0
    public String buildDrivingUrl(String originLongitude, String originLatitude,
                                    String destLongitude, String destLatitude) {
        return UriComponentsBuilder.fromHttpUrl(AmapConfigConstants.DIRECTION_URL)
                .queryParam("origin", formatCoordinate(originLongitude, originLatitude))
                .queryParam("destination", formatCoordinate(destLongitude, destLatitude))
                .queryParam("extensions", "base")
                .queryParam("output", "json")
                .queryParam("key", mapKey)
                .build()
                .toUriString();
    }



    private String formatCoordinate(String longitude, String latitude) {
        return String.join(",", longitude, latitude);
    }
}
